<template>
  <div>
    <el-button mb-2 @click="toggle">切换</el-button>
    <el-button mb-2 @click="toggle(locale.name = 'zhCn')">中</el-button>
    <el-button mb-2 @click="toggle(locale.name = 'en')">英</el-button>
    <br />
    <span>{{ $t('menus.home') }}</span>
    <br>
    <span>{{ $t('buttons.login') }}</span>
    <el-config-provider :locale="locale">
      <el-text class="mx-1" type="primary" default="Primary"></el-text>
      <el-table mb-1 :data="[]" />
      <el-pagination :total="100" />
    </el-config-provider>
  </div>
</template>
  
<script lang="ts" setup>
import { computed, ref } from 'vue'
import zhCn from 'element-plus/es/locale/lang/zh-cn' // 简体中文
import en from 'element-plus/es/locale/lang/en'
import i18n from './i18n'// English

const language = ref('zhCn')
const locale = computed(() => (language.value === 'zhCn' ? zhCn : en))
const toggle = (a) => {
  language.value = language.value === 'zhCn' ? 'en' : 'zhCn'
  // i18n.global.locale.value = locale
  // i18n.global.

  let loation = locale.value
  console.log(loation.name)
  tab(a || loation.name)
  console.log(i18n.global.locale.value)
}

const tab = (a) => {
  i18n.global.locale.value = a

}
</script>
  